#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "firewallHint.h"

// 分隔线长度
#define DIV_LENGTH 104
// 生成分隔线
#define divide \
for (int i = 0; i < DIV_LENGTH; i++)\
    printf("-");\
printf("\n")

void selectHint(void)
{
    printf("Please choose a mode from the following choices: \n");
    printf("1. Dynamic mode (config by packages you've received)\n");
    printf("2. Static mode (directly input you config)\n");
    printf("3. Config by port\n");
    printf("4. Config by protocol\n");
    printf("5. Config by network card\n");
    printf("6. List all the configuration\n");
    printf("q. quit the application\n");
}

void showPkg(int amount, Package * IPsets)
{
    divide;
    printf("|%-*s|\n", DIV_LENGTH - 2, \
        "Got following packages from the Internet:");
    divide;
    printf("|%3s | %-23s | %-23s | %-24s | %-7s | %-6s |\n", \
        "no.", "Source", "Destination", "Time", "Proto", "NCard");
    divide;

    for (int i = 0; i < amount; i++)
    {
        srand(time(NULL));
        time_t t = rand() % 256 + (IPsets + i)->timestamp;
        char * timep = ctime(&t);
        *(timep + 24) = '\0';
        printf("|%2d. | "IPformat" : %5d | "IPformat" : %5d | %24s | %-7s | %-6s |\n", \
            i + 1, format_IP((IPsets + i)->srcIP), (IPsets + i)->srcPort, \
            format_IP((IPsets + i)->dstIP), (IPsets + i)->dstPort, timep, \
            protocol[(IPsets + i)->protocol], netcard[(IPsets + i)->netcard]);
        divide;
    }
}

void showCfg(char* filename, char* cmd)
{
    sprintf(cmd, "more %s", filename);
    system(cmd);
    printf("\n");
}